import requests
from requests.auth import HTTPBasicAuth

url = 'http://127.0.0.1:8000/admin/'
# allow_redirects 默认是true 重定向到登录页面
# response = requests.get(url)
# print(response.text)


# response = requests.get(url,allow_redirects=False)
#
# print(response.status_code)
# print(response.headers.get('location'))
#
# location = response.headers.get('location')
# location = f'http://127.0.0.1:8000{location}'
# response = requests.get(location)
# print(response.status_code)
# print(response.text)

# headers = {
#     # 'cookie':'sessionid=wq5syph1i43udbv2vhh4znwwqwyynrc6'
# }
#
# cookies = {
#     'sessionid':'wq5syph1i43udbv2vhh4znwwqwyynrc6'
# }
# # response = requests.get(url, headers=headers)
# response = requests.get(url, cookies=cookies, headers=headers)
# print(response.status_code)
# print(response.text)



# 后端加
response = requests.get(url,auth=HTTPBasicAuth('admin', '123456'))
print(response.status_code)
print(response.text)